/**
 * 
 */
package hr.fer.zemris.annotator;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import hr.fer.zemris.annotator.gui.ApplicationParametersView;
import hr.fer.zemris.annotator.services.CommandBuilderService;
import hr.fer.zemris.annotator.services.ProfilingDataParsingService;

import javax.swing.SwingUtilities;
import javax.swing.UIManager;

/**
 * @author dajan
 * 
 */
public class Test {

	public static void main(String[] args) throws IOException,
			InterruptedException {

		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				// Turn off metal's use of bold fonts
				UIManager.put("swing.boldMetal", Boolean.FALSE);
				ApplicationParametersView initialView = new ApplicationParametersView();
				initialView.setVisible(true);
			}
		});

		// String cmd =
		// "cd ..; cd ..; cd scripts; ls; . profile_c_code.sh /home/dajan/development/dipl/c_examples/ sort_example.o /home/dajan/sort_example3.txt";
		// ProcessBuilder pb = new ProcessBuilder("bash", "-c", cmd);
		// pb.redirectErrorStream(true); // use this to capture messages sent to
		// // stderr
		// Process shell = pb.start();
		// InputStream shellIn = shell.getInputStream();
		// BufferedReader shellReader = new BufferedReader(new
		// InputStreamReader(shellIn));
		// String status = "";
		// // this captures the
		// // output from the
		// // command
		// shell.waitFor(); // wait for the shell to finish
		// // and get the return code
		// // at this point you can process the output issued by the command
		// // for instance, this reads the output and writes it to System.out:
		// while (true) {
		// String line = shellReader.readLine();
		// if(line == null) break;
		// status += line;
		// status += System.getProperty("line.separator");
		// }
		//
		// System.out.println(status);
		// // close the stream
		// try {
		// shellIn.close();
		// } catch (IOException ignoreMe) {
		// }
		
//		ProfilingDataParsingService
//		.parseGprofileOutput("/home/dajan/PerformanceAnnotatorOutput.txt");
		
		//BufferedReader reader = new BufferedReader(new FileReader("/home/dajan/development/dipl/c_examples/sort_example.c"));
		String source = "";
		
//		while (true){
//		
//			String line = reader.readLine();
//			
//			if(line == null) break;
//			
//			source += line;
//		}
		
//		source = CommandBuilderService.getStringFromFile(new File("/home/dajan/development/dipl/c_examples/sort_example.c"));
//		//iza s* (?={)
//		Pattern pattern = Pattern.compile("((?<=[\\s:~])(\\w+)\\s*\\(([\\w\\s,<>\\[\\].=&':/*]*?)\\)\\s*(const)?\\s*(?=\\{))");
//		Matcher matcher = pattern.matcher(source);
//		
//		while (matcher.find()) {
//			System.out.print("Start index: " + matcher.start());
//			//matcher.replaceAll(replacement)
//			System.out.print(" End index: " + matcher.end() + " ");
//			System.out.println(matcher.group());
//		}
		
		
		
		//source = matcher.replaceAll("daaajaan");
		
		//String str = CommandBuilderService.getOutputFilePath(new File ("/home/dajan/development/dipl/c_examples/sort_example.c"));

		System.out.println(source);
	}

}
